import request from './request';
import PremissionCodes from '@/constants/premissions';

export const login = (params: any) => {
  return request<string>({
    url: '/login',
    method: 'post',
    params
  });
};

export const loginOut = () =>
  request({
    method: 'get',
    url: '/logout'
  });

// 查询用户信息
export const getUserInfoApi = () =>
  request<UserInfomation>({
    method: 'get',
    url: 'getUserInfo'
  });

// 查询用户权限
export const getUserPremissionApi = () =>
  request<{
    menuList: Array<MenuInfo>;
    permissionCodes: PremissionCodes[];
  }>({
    method: 'get',
    url: 'getPermission'
  });

export interface TreeNodeData {
  id: string;
  name: string;
  children?: TreeNodeData[];
}

export interface DeptAndUser {
  id: string;
  name: string;
  personals: Array<{
    uid: string;
    name: string;
    roles: Array<{
      roleId: string;
      roleName: string;
    }>;
  }>;
  children?: DeptAndUser[];
}

export const getDeptData = () => {
  return request<TreeNodeData[]>({
    url: 'department/list',
    method: 'get'
  });
};

export const getDeptUserData = () => {
  return request<DeptAndUser[]>({
    url: 'deptAndUser/list',
    method: 'get'
  });
};

export const getUserList = () => {
  return request<UserItem[]>({
    url: 'user/list',
    method: 'get'
  });
};

export const getMockList = () => {
  return request<Array<any>>({
    url: 'long/list',
    method: 'get'
  });
};
